package com.swizipuremvc.app.user.commands
{
	import com.swizipuremvc.app.user.proxies.interfaces.IDashboardProxy;
	import com.swizipuremvc.core.common.FacadeType;
	import com.swizipuremvc.core.common.NoteType;
	import com.swizipuremvc.core.common.ProxyType;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.ResultEvent;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	
	public class DashboardCommand extends SimpleCommand
	{
		public function DashboardCommand()
		{
			super();
		}
		
		override public function execute(notification:INotification):void
		{
			var params:ArrayCollection = notification.getBody() as ArrayCollection;
			var user:String = params.getItemAt(0) as String;
			var password:String = params.getItemAt(1) as String;
			this.initializeNotifier(FacadeType.DASHBOARD_FACADE.toString());
			this.getProxy().authenticateUser(user,password,onResult);
		}
		
		public function onResult(event:ResultEvent):void
		{
				this.initializeNotifier(FacadeType.DASHBOARD_FACADE.toString());
				this.sendNotification(NoteType.LOGON_RESULT_RECEIVE_HANDLER.toString(),event.result);
		}
		
		public function getProxy():IDashboardProxy
		{
			return this.facade.retrieveProxy(ProxyType.DASHBOARD_PROXY.toString()) as IDashboardProxy;
		}
	}
}